package com.faith.dynamic.bean;

import com.faith.dynamic.enums.FaithSysExceptionEnum;
import lombok.Data;

/**
 * @ClassName BaseRequestObj$
 * @Description 基础响应结构
 * @Author faith$
 * @Date 2019/7/25 14:28
 * @Version 1.0
 **/
@Data
public class BaseResponseObj<T> {
    private String code = "200";

    private String message = "Request Successfully";

    private T data = null;

    public BaseResponseObj() {
    }
    public BaseResponseObj(T data) {
        this.data = data;
    }

    public BaseResponseObj(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public BaseResponseObj(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static <T>  BaseResponseObj<T>  response(FaithSysExceptionEnum sysExceptionEnum){
        return new BaseResponseObj(sysExceptionEnum.getCode(),sysExceptionEnum.getMessage());
    }

    public static <T>  BaseResponseObj<T>  response(FaithSysExceptionEnum sysExceptionEnum, T data){
        return new BaseResponseObj(sysExceptionEnum.getCode(),sysExceptionEnum.getMessage(),data);
    }

    public static <T> BaseResponseObj<T> ok(T data){
        return new BaseResponseObj<T>("200", "Request Successfully", data);
    }

}
